﻿using System;
using System.Collections.Generic;
using System.Text;
using XCore.Domain.Data;
using StackExchange.Redis;
using XCore.Redis;

namespace SaaS.Model.Dto.Sites
{
    public struct SiteModel
    {
        /// <summary>
        /// 站点Id
        /// </summary>
        public int SiteId;
        /// <summary>
        /// 租户名称
        /// </summary>
        public string Name;
        /// <summary>
        /// 密钥
        /// </summary>
        public string SecretKey;
        /// <summary>
        /// 是否宿主
        /// </summary>
        public bool IsHost;
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public string ConnectionString;
        /// <summary>
        /// 数据库类型
        /// </summary>
        public DatabaseType? Type;
        /// <summary>
        /// 前缀
        /// </summary>
        public string Domain;

        public static implicit operator SiteModel(HashEntry[] hash)
        {
            return hash.GetReidsHashValue<SiteModel>();
        }

        public static implicit operator HashEntry[](SiteModel tenant)
        {
            return tenant.GetRedisHashEntry();
        }
        public static implicit operator bool(SiteModel tenant)
        {
            return tenant.SiteId != 0;
        }
    }
}
